'use strict';

/* Controllers */
app.controller('houseOwnerLoanListDetailCtl', function($scope,$compile,ngDialog,uiLoad) {

    var rentTypeObj = {
        0: "年付",
        1: "季付",
        2: "月付"
    };
    var applyTypeObj = {
        0: "支付包",
        1: "微信",
        2: "现金"
    };
    $scope.checkType = {};
    $scope.houseType = {}
    $scope.checkTypeArray = [{ "name": "未申请", "value": "0" }, { "name": "申请中", "value": "1" }, { "name": "申请通过", "value": "2" }, { "name": "装修中", "value": "3" }, { "name": "装修完成", "value": "3" }];
    if($scope.queryParams){

    }
    $scope.queryParams = {
        'decorateStatus': $scope.houseType.selected || 0,
        'startTime': $scope.startTime,
        'endTIme': $scope.endTIme,
        'nameCode': $scope.nameCode
    }

    $scope.queryUser = function() {
        $scope.dataTable.fnClearTable()
    };
    $scope.tableLoanDatas = {
        "sAjaxSource": "4040",
        "aoColumns": [{
            "mDataProp": "repaymentDateString",
            "sTitle": "还款周期",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "repaymentDate",
            "sTitle": "还款日",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "installment",
            "sTitle": "期数",
            "sDefaultContent": "",
            "sClass": "center"
        },{
            "mDataProp": "monthlyRent",
            "sTitle": "还款金额",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "leaseType",
            "sTitle": "还款时间",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "houseType",
            "sTitle": "还款状态",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "operate",
            "sTitle": "操作111",
            "sDefaultContent": "",
            "sClass": "center handle-td"
        }],
        "fnRowCallback": function(nRow, aData, iDisplayIndex) {
            var btnStr = "";
            btnStr += "<a href='javascript:;' class='btn btn-yellow' style='margin-right:10px;' ng-click='decorateReview(\"" + aData.decorateId + "\")'>支付</a>";
            $(nRow).find(".handle-td").append($compile(btnStr)($scope));
        },
        "fnServerParams": function(aoData) {
            aoData.push({
                'name': 'queryParams',
                'value': $scope.queryParams
            });
            return aoData;
        }
    };
    $scope.dataTable = undefined;

          // "landlordId": "40155814-52b1-4cf2-814a-724f770bbd5b",
          // "decorateId": "5bea9b36-1f94-4bf6-af8a-e2ed3117f53b",
          // "houseId": "e55c6e9f-d6b4-46d0-94c5-e20063ee0611",

    $scope.decorateWithdraw = function (decorateId) {

    }
    
    $scope.decorateReview = function (decorateId) {
        ngDialog.openConfirm({
          template: 'js/module/decorate/review.html',
          resolve: {
            load: function() {
              return uiLoad.load(['js/module/decorate/review.js'])
            }
          },
          data:{
            decorateId:decorateId
          },
          scope: $scope,
          width: 1200,
          // height: 700
        }).then(function(data) {

        }, function(reason) {

        });
    }
    
    // 回调函数,返回实例化的jquery 插件对象
    $scope.initFinish = function(dataTable) {
        $scope.dataTable = dataTable;
    }
    $('#example thead').on('click', 'th', function() {
        // var data = $('#example').DataTable().row( this ).data();
        // alert('You clicked on  row');
    });
    $('#example tbody').on('click', 'span#edit', function() {
        var data = $('#example').DataTable().row($(this).parents('tr'));
        alert("查看修改：" + data[0]);
    });
    $('#example tbody').on('click', 'span#del', function() {
        // var data = $('#example').DataTable().row($(this).parents('tr')).data();
    });

});
